package CreateFactroy.Protoyepe;

// 原型接口
interface Prototype {
    Prototype clone();
}

// 具体原型类
class ConcretePrototype implements Prototype {
    private String attribute;

    public ConcretePrototype(String attribute) {
        this.attribute = attribute;
    }

    @Override
    public Prototype clone() {
        // 创建一个新对象并将当前对象的属性复制过去
        return new ConcretePrototype(this.attribute);
    }

    public String getAttribute() {
        return attribute;
    }

    public void setAttribute(String attribute) {
        this.attribute = attribute;
    }
}

// 客户端
public class Client {
    public static void main(String[] args) {
        // 创建原型对象
        ConcretePrototype prototype = new ConcretePrototype("Initial Attribute");

        // 克隆原型对象
        ConcretePrototype clonedPrototype = (ConcretePrototype) prototype.clone();

        // 修改克隆对象的属性
        clonedPrototype.setAttribute("Modified Attribute");

        // 打印原型对象和克隆对象的属性
        System.out.println("Prototype Attribute: " + prototype.getAttribute());
        System.out.println("Cloned Prototype Attribute: " + clonedPrototype.getAttribute());
    }
}
